package com.zlf.web_generator_code;

import cn.org.rapid_framework.generator.GeneratorFacade;
import cn.org.rapid_framework.generator.GeneratorProperties;
import org.junit.Test;

import java.io.File;

/**
 * Created by Administrator on 2016/12/26.
 *
 * @author zlf
 */
public class GeneratorCode {


    @Test
    public void testCreateEntity() throws Exception {
        //模板路径
        String templatePath = "template_model";
        GeneratorFacade g = new GeneratorFacade();
        File templateFile = new File(GeneratorCode.class.getClassLoader().getResource(templatePath).getFile());
        System.out.println(templateFile.getAbsoluteFile());
        g.getGenerator().addTemplateRootDir(templateFile);
        //删除生成器的输出目录//
//        g.deleteOutRootDir();
//        g.generateByAllTable(); //添加该数据库的所有表
        g.generateByTable("app_user");
        System.out.println(GeneratorProperties.getRequiredProperty("outRoot"));
        System.out.println("----------------");
        Runtime.getRuntime().exec("cmd.exe /c start"+ GeneratorProperties.getRequiredProperty("outRoot"));
    }

    @Test
    public void testCreateService()throws Exception {
        //模板路径
        String templatePath = "template_service";
        GeneratorFacade g = new GeneratorFacade();
        g.getGenerator().addTemplateRootDir(templatePath);
        //删除生成器的输出目录//
//        g.deleteOutRootDir();
//        g.generateByAllTable(); //添加该数据库的所有表
        g.generateByTable("role");
        Runtime.getRuntime().exec("cmd.exe /c start"+ GeneratorProperties.getRequiredProperty("outRoot"));
    }

    @Test
    public void testCreateHibernate()throws Exception {
        //模板路径
        String templatePath = "template_h_a";
        GeneratorFacade g = new GeneratorFacade();
        g.getGenerator().addTemplateRootDir(templatePath);
//        g.deleteOutRootDir();
        //删除生成器的输出目录//
//        g.deleteOutRootDir();
//        g.generateByAllTable(); //添加该数据库的所有表
        g.generateByTable("app_user");
        Runtime.getRuntime().exec("cmd.exe /c start"+ GeneratorProperties.getRequiredProperty("outRoot"));
    }
}
